﻿using System;
using System.Text;

namespace TimerTask.Common.Utils
{
    public class Base64Util
    {
        public static byte[] Base64ToBytes(string strModified)
        {
            return Convert.FromBase64String(strModified);
        }


        /// <summary>
        /// 将原文转为Base64
        /// author:肖阳
        /// 2016-10-07 15:35:10
        /// </summary>
        /// <param name="strOriginal"></param>
        /// <returns></returns>
        public static string EnBase64(string strOriginal)
        {
            byte[] byt = Encoding.UTF8.GetBytes(strOriginal);

            return Convert.ToBase64String(byt);
        }


        /// <summary>
        /// 将Base64密文转为明文
        /// author:肖阳
        /// 2016-10-07 15:35:13
        /// </summary>
        /// <param name="base64Str"></param>
        /// <returns></returns>
        public static string DeBase64(string base64Str)
        {
            try
            {
                return Encoding.UTF8.GetString(Convert.FromBase64String(base64Str));
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }
    }
}
